﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Upeu.Matricula.Data.Entities;

namespace Upeu.Matricula.Data.Business
{
    public class CuentaTutorBusiness
    {
        //CRUD + Logic business or constrains
        public static IList<CuentaTutor> GetListByFilter(string filter)
        {
            //throw new NotImplementedException();
            using (UpeuMatriculaDbContext ctx = new UpeuMatriculaDbContext()) // conexion a la db
            {
                return ctx.CuentaTutors.Where(t => t.Estado.Contains(filter)).ToList(); //Clientes tiene CRUD
            }
        }
        public static CuentaTutor Create(CuentaTutor cuentatutor)
        {
            using (UpeuMatriculaDbContext ctx = new UpeuMatriculaDbContext())
            {
                CuentaTutor cuentatutorDB = ctx.CuentaTutors.Add(cuentatutor);
                ctx.SaveChanges();
                return cuentatutorDB;
            }
        }
        public static CuentaTutor Update(CuentaTutor cuentatutor)
        {
            using (UpeuMatriculaDbContext ctx = new UpeuMatriculaDbContext())
            {
                ctx.Entry(cuentatutor).State = EntityState.Modified;
                ctx.SaveChanges();
                return cuentatutor;
            }
        }
        public static CuentaTutor GetById(Guid id)
        {
            using (UpeuMatriculaDbContext ctx = new UpeuMatriculaDbContext())
            {
                CuentaTutor c = ctx.CuentaTutors.Find(id);
                if (c == null)
                {
                    throw new Exception("person no found in data base.");
                }
                return c;
            }
        }
        public static void Delete(Guid id)
        {
            using (UpeuMatriculaDbContext ctx = new UpeuMatriculaDbContext())
            {
                CuentaTutor c = ctx.CuentaTutors.Find(id);
                if (c == null)
                {
                    throw new Exception("person no found in data base.");
                }
                ctx.CuentaTutors.Remove(c);
                ctx.SaveChanges();
            }
        }
    }
}
